﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Colors.xaml" />

        <ResourceDictionary>

            <!--  General  -->
            <SolidColorBrush x:Key="BackgroundHighlighted" Color="#54545C" />
            <SolidColorBrush x:Key="BorderBrushHighlighted" Color="#6A6A75" />
            <SolidColorBrush x:Key="BackgroundSelected" Color="#CCcb0000" />
            <SolidColorBrush x:Key="BorderBrushSelected" Color="#1C97EA" />
            <SolidColorBrush x:Key="BackgroundNormal" Color="#3F3F46" />
            <SolidColorBrush x:Key="BorderBrushNormal" Color="#54545C" />

            <!--  Close Button  -->
            <SolidColorBrush x:Key="CloseButtonBackgroundHighlighted" Color="#39ADFB" />
            <SolidColorBrush x:Key="CloseButtonBackgroundPressed" Color="#084E7D" />
            <SolidColorBrush x:Key="CloseButtonStroke" Color="#AAFFFFFF" />
            <SolidColorBrush x:Key="CloseButtonStrokeHighlighted" Color="#FFFFFF" />

        </ResourceDictionary>

    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="StandardTabControl"
           TargetType="{x:Type TabControl}">
        <Style.Resources>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="FocusVisualStyle"
                        Value="{x:Null}" />
                <Setter Property="Background"
                        Value="Transparent" />
                <Setter Property="Foreground"
                        Value="{StaticResource Foreground}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TabItem}">
                            <Grid Height="30"
                                  Background="{TemplateBinding Background}"
                                  SnapsToDevicePixels="true">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="25" />
                                </Grid.ColumnDefinitions>
                                <ContentPresenter Grid.Column="0"
                                                  Margin="10,0,10,0"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  ContentSource="Header" />
                                <Button Grid.Column="1"
                                        Width="15"
                                        Height="15"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        Command="{Binding Path=CloseCommand}"
                                        DockPanel.Dock="Right">
                                    <Button.Style>
                                        <Style TargetType="{x:Type Button}">
                                            <Setter Property="Background"
                                                    Value="Transparent" />
                                            <Setter Property="Cursor"
                                                    Value="Hand" />
                                            <Setter Property="Focusable"
                                                    Value="False" />
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type Button}">
                                                        <Grid Background="{TemplateBinding Background}">
                                                            <Path x:Name="ButtonPath"
                                                                  Margin="2"
                                                                  HorizontalAlignment="Center"
                                                                  VerticalAlignment="Center"
                                                                  Data="M0,0 L1,1 M0,1 L1,0"
                                                                  Stretch="Uniform"
                                                                  Stroke="{DynamicResource CloseButtonStroke}"
                                                                  StrokeEndLineCap="Flat"
                                                                  StrokeStartLineCap="Flat"
                                                                  StrokeThickness="2" />
                                                        </Grid>
                                                        <ControlTemplate.Triggers>
                                                            <MultiDataTrigger>
                                                                <MultiDataTrigger.Conditions>
                                                                    <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TabItem}}"
                                                                               Value="false" />
                                                                    <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TabItem}}"
                                                                               Value="false" />
                                                                </MultiDataTrigger.Conditions>
                                                                <MultiDataTrigger.Setters>
                                                                    <Setter Property="Visibility"
                                                                            Value="Hidden" />
                                                                </MultiDataTrigger.Setters>
                                                            </MultiDataTrigger>
                                                            <Trigger Property="IsEnabled"
                                                                     Value="False">
                                                                <Setter Property="Visibility"
                                                                        Value="Hidden" />
                                                            </Trigger>
                                                            <Trigger Property="IsMouseOver"
                                                                     Value="True">
                                                                <Setter Property="Background"
                                                                        Value="{DynamicResource CloseButtonBackgroundHighlighted}" />
                                                                <Setter TargetName="ButtonPath"
                                                                        Property="Stroke"
                                                                        Value="{DynamicResource CloseButtonStrokeHighlighted}" />
                                                            </Trigger>
                                                            <Trigger Property="IsPressed"
                                                                     Value="true">
                                                                <Setter Property="Background"
                                                                        Value="{DynamicResource CloseButtonBackgroundPressed}" />
                                                                <Setter TargetName="ButtonPath"
                                                                        Property="Stroke"
                                                                        Value="{DynamicResource CloseButtonStroke}" />
                                                                <Setter TargetName="ButtonPath"
                                                                        Property="Margin"
                                                                        Value="2.5,2.5,1.5,1.5" />
                                                            </Trigger>
                                                        </ControlTemplate.Triggers>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </Button.Style>
                                </Button>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected"
                                         Value="false">
                                    <Setter Property="Background"
                                            Value="Transparent" />
                                </Trigger>
                                <Trigger Property="IsMouseOver"
                                         Value="true">
                                    <Setter Property="Background"
                                            Value="{DynamicResource BorderBrushSelected}" />
                                </Trigger>
                                <Trigger Property="IsSelected"
                                         Value="true">
                                    <Setter Property="Background"
                                            Value="{DynamicResource BackgroundSelected}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Style.Resources>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid KeyboardNavigation.TabNavigation="Local">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Border Background="Transparent"
                                BorderBrush="{DynamicResource BackgroundSelected}"
                                BorderThickness="0,0,0,3">
                            <TabPanel Name="HeaderPanel"
                                      Margin="0,0,4,-1"
                                      Panel.ZIndex="1"
                                      IsItemsHost="True"
                                      KeyboardNavigation.TabIndex="1" />
                        </Border>
                        <Border Grid.Row="1"
                                Background="{DynamicResource Background}" />
                        <ContentPresenter Name="PART_SelectedContentHost"
                                          Grid.Row="1"
                                          ContentSource="SelectedContent" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <DataTemplate x:Key="ClosableTabItemTemplate">
        <DockPanel>
            <ContentPresenter VerticalAlignment="Center"
                              Content="{Binding DisplayName}">
                <ContentPresenter.Resources>
                    <Style TargetType="TextBlock">
                        <Setter Property="Foreground"
                                Value="{StaticResource Foreground}" />
                        <Setter Property="FontSize"
                                Value="20" />
                    </Style>
                </ContentPresenter.Resources>
            </ContentPresenter>
        </DockPanel>
    </DataTemplate>

    <!--  This template explains how to render the 'Workspace' content area in the main window.  -->
    <DataTemplate x:Key="WorkspacesTemplate">
        <TabControl Margin="0"
                    IsSynchronizedWithCurrentItem="True"
                    ItemTemplate="{StaticResource ClosableTabItemTemplate}"
                    ItemsSource="{Binding}"
                    Style="{DynamicResource StandardTabControl}" />
    </DataTemplate>
</ResourceDictionary>